<template>
	<view class="authentication">
		<view class="listItem">
			<view class="lable">
				姓名
			</view>
			<input class="inputitem" type="text" v-model="check_realname" placeholder="请输入姓名">
		</view>
		<view class="listItem">
			<view class="lable">
				手机号
			</view>
			<input class="inputitem" type="number" v-model="check_mobile" placeholder="请输入手机号">
		</view>
		<view class="listItem">
			<view class="lable">
				银行卡
			</view>
			<view class="inputitem"
				style="display: flex;align-items: center;justify-content: space-between;padding-right: 30rpx;box-sizing: border-box;"
				@click="handleCartList">
				<view v-if="bank_card== null" class="" style="color: grey;">
					请添加银行卡
				</view>
				<view v-else class="">
					{{bank_card}}
				</view>
				<image src="/static/image/right.png" mode="" style="width: 18rpx;height: 28rpx;"></image>
			</view>
		</view>

		<view class="listItem">
			<view class="lable">
				支付宝账号
			</view>
			<view class="inputitem"
				style="display: flex;align-items: center;justify-content: space-between;padding-right: 30rpx;box-sizing: border-box;"
				@click="handleZhiFubao">
				<view v-if="alipay_account== null" class="" style="color: grey;">
					请添加支付宝账号
				</view>
				<view v-else class="">
					{{alipay_account}}
				</view>
				<image src="/static/image/right.png" mode="" style="width: 18rpx;height: 28rpx;"></image>
			</view>
		</view>

		<view class="listItem">
			<view class="lable">
				微信收款码
			</view>
			<view class="uploadBox" @click="handleUpload">
				<image v-if="wx_code ==''" src="@/static/image/upload.png" mode="" style="width: 100%;height: 100%;" ></image>
				<image v-else :src="wx_code" mode="" style="width: 100;height: 100;"></image>
			</view>
		</view>
		<view class="exit">
			<view class="" @click="handleUpload">
				更换
			</view>
			<image src="/static/image/right.png" mode="" style="width: 14rpx;height: 20rpx;margin-left: 6rpx;"></image>
		</view>

		<view class="btns" @click="handleSubmit">
			提交
		</view>

	</view>
</template>

<script>
	import {
		checkuser,
		userinfo
	} from "@/api/api.js"

	export default {
		data() {
			return {
				check_realname: "", //认证姓名，
				check_mobile: "", //认证手机号
				bank_name: "", //银行名称
				bank_khh: "", //开户行
				bank_nickname: "", //持卡人
				bank_card: "", //卡号
				alipay_name: "", //支付宝真实姓名
				alipay_account: "", //支付宝账号
				wx_code: "", //微信收款码地址
				cartValue: null,
				zhifuBao: null,
				token: "",
			}
		},
		onShow() {
			if (uni.getStorageSync("yinhangData")) {
				this.bank_name = uni.getStorageSync("yinhangData").bank_name
				this.bank_khh = uni.getStorageSync("yinhangData").bank_khh
				this.bank_nickname = uni.getStorageSync("yinhangData").bank_nickname
				this.bank_card = uni.getStorageSync("yinhangData").bank_card
			}
			if (uni.getStorageSync("zhifubaoData")) {
				this.alipay_name = uni.getStorageSync("zhifubaoData").alipay_name
				this.alipay_account = uni.getStorageSync("zhifubaoData").alipay_account
			}
		},
		onLoad() {
			if (!uni.getStorageSync("token")) {
				uni.reLaunch({
					url: "../login/index"
				})
				return
			}
			this.token = uni.getStorageSync("token")
			this.handleGetuserinfo()
		},
		methods: {
		

			async handleGetuserinfo() {
				let res = await userinfo()
				this.pageData = res.data
				console.log("用户信息", res)
				
				this.check_realname = res.data.check_realname
				this.check_mobile = res.data.check_mobile
				this.bank_name = res.data.bank_name
				this.bank_khh = res.data.bank_khh
				this.bank_nickname = res.data.bank_nickname
				this.bank_card = res.data.bank_card
				this.alipay_name = res.data.alipay_name 
				this.alipay_account = res.data.alipay_account
				this.wx_code = res.data.wx_code ? res.data.wx_code : ""
			},
			async handleSubmit() {
				let data = {
					check_realname: this.check_realname == null || this.check_realname == '' ? "" : this.check_realname,
					check_mobile: this.check_mobile == null || this.check_mobile == '' ? "" : this.check_mobile,
					bank_name: this.bank_name == null || this.bank_name == '' ? "" : this.bank_name,
					bank_khh: this.bank_khh  == null || this.bank_khh == '' ? "" : this.bank_khh,
					bank_nickname: this.bank_nickname == null || this.bank_nickname == '' ? "" : this.bank_nickname,
					bank_card: this.bank_card  == null || this.bank_card == '' ? "" : this.bank_card,
					alipay_name: this.alipay_name == null || this.alipay_name == '' ? "" : this.alipay_name,
					alipay_account: this.alipay_account == null || this.alipay_account == '' ? "" : this.alipay_account,
					wx_code: this.wx_code
				}
				console.log("认证数据", data)
				let res = await checkuser(data)
				if (res.code == 1000) {
					uni.showToast({
						title: "认证成功",
						icon: "none",
						duration: 1500
					});
					uni.removeStorageSync("yinhangData")
					uni.removeStorageSync("zhifubaoData")
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 2000)
				}

			},
			handleUpload() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log("tempFilePaths", tempFilePaths)
						uni.uploadFile({
							url: 'http://admin.jinsekeji.com.cn/api/login/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								// "Content-Type": "application/form-data",
								"Authorization": 'Bearer' + ' ' + that.token
							},
							success: (uploadFileRes) => {
								// console.log("33333", uploadFileRes)
								that.wx_code = (JSON.parse(uploadFileRes.data).data)
								console.log("图片", that.wx_code)
							},
							fail(e) {
								console.log("上传图片", e)
							}
						});
					}
				});


			},
			handleCartList() {
				uni.navigateTo({
					url: "./addCart"
				})
			},
			handleZhiFubao() {
				uni.navigateTo({
					url: "./addZhiFubao"
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.btns {
		width: 542rpx;
		height: 80rpx;
		background: #04767C;
		border-radius: 512rpx 512rpx 512rpx 512rpx;
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		margin: 0 auto;
		margin-top: 50rpx;
	}

	page {
		width: 100%;
		min-height: 100%;
		background-color: #ffffff;
	}

	.authentication {
		width: 100%;
		padding: 0 30rpx;
		padding-top: 30rpx;
		box-sizing: border-box;

		.listItem {
			margin-top: 24rpx;

			.lable {
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 42rpx;
			}

			.inputitem {
				width: 100%;
				height: 88rpx;
				background: #F1F1F1;
				opacity: 1;
				text-indent: 22rpx;
				margin-top: 16rpx;
				font-size: 30rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: 400;
				line-height: 88rpx;
			}

			.uploadBox {
				width: 202rpx;
				height: 202rpx;
				background: #F1F1F1;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				text-align: center;
				line-height: 202rpx;
				margin-top: 16rpx;
			}

		}

		.exit {
			width: 154rpx;
			height: 42rpx;
			background: #EAEAEA;
			border-radius: 404rpx 404rpx 404rpx 404rpx;
			font-size: 24rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #3D3D3D;
			line-height: 42rpx;
			display: flex;
			align-items: center;
			padding-left: 44rpx;
			box-sizing: border-box;
			margin-top: 24rpx;
			margin-left: 24rpx;
		}
	}
</style>